package cn.itcast.javaobject;

/**
 * @title: MiGong
 * @Author Zhou
 * @Date: 2021/12/30 13:45
 * @Version 1.0
 */
public class MiGong {
    public static void main(String[] args) {
        int[][] map = new int[8][7];
        for (int i = 0; i < 7; i++) {
            map[0][i] = 1;
            map[7][i] = 1;
        }

        for (int i = 0; i < 8; i++) {
            map[i][0] = 1;
            map[i][6] = 1;
        }
        map[3][1] = 1;
        map[3][2] = 1;
        map[2][2] = 1;

        System.out.println("====当前的地图为====");
        for (int[] ints : map) {
            for (int anInt : ints) {
                System.out.print(anInt + " ");//输出一行
            }
            System.out.println();
        }
        T t = new T();
        t.findWay(map, 1, 1);
        System.out.println("t = " + t);
        //8行，7列
        System.out.println("====寻路地图====");
        for (int[] ints : map) {
            for (int anInt : ints) {
                System.out.print(anInt + " ");//输出一行
            }
            System.out.println();
        }
    }
}

class T {
    public boolean findWay(int[][] map, int i, int j) {
        if (map[6][5] == 2) {//说明已经找到
            return true;
        } else {
            if (map[i][j] == 0) {//当前这个位置 0,说明表示可以走
//我们假定可以走通
                map[i][j] = 2;
//使用找路策略，来确定该位置是否真的可以走通
//下->右->上->左
                if (findWay(map, i + 1, j)) {//先走下
                    return true;
                } else if (findWay(map, i, j + 1)) {//右
                    return true;
                } else if (findWay(map, i - 1, j)) {//上
                    return true;
                } else if (findWay(map, i, j - 1)) {//左
                    return true;
                } else {
                    map[i][j] = 3;
                    return false;
                }
            } else { //map[i][j] = 1 , 2, 3
                return false;
            }
        }
    }

}
